<template>
  <div class="content">
    <h3>叩丁狼电商运营平台</h3>
    <span class="icon" @click="AsideModel.changeIsShow">
      <el-icon size="20" color="#fff"><Menu /></el-icon>
    </span>
    <div class="right">
      <el-dropdown @command="commandHandle">
        <span class="el-dropdown-link">
          {{ UserStore.username }}
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="index">首页</el-dropdown-item>
            <el-dropdown-item command="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Menu, ArrowDown } from "@element-plus/icons-vue";
import { AsideModeStore } from "@/store/Aside";
import { useUserStore } from "@/store/user";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { logout } from "@/common";

const AsideModel = AsideModeStore();
const UserStore = useUserStore();
const router = useRouter();

const commandHandle = (command: string) => {
  // console.log(command);
  if (command === "index") {
    // 跳转到首页
    router.push("/index");
  } else if (command === "logout") {
    // 退出登录
    logout(
      () => {
        // 自己把登出的请求实现
      },
      () => {
        // 提示
        ElMessage.success("退出成功~");
      }
    );
  }
};
</script>

<style scoped lang="less">
.content {
  position: relative;
  h3 {
    display: inline-block;
    padding: 0 20px;
    line-height: 70px;
    font-weight: 400;
    font-size: 24px;
    color: #fff;
  }
  .right {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 20px;
    // background-color: red;

    :deep(.el-dropdown) {
      color: #fff;
    }
  }
}
</style>
